package client;

import java.io.Serializable;

public class ReportControl implements Serializable{
	
	/**
	 * saves details from data base for tables in GUI
	 */
	public static Object[][] data = null;
	/**
	 * storage and sends details to echo server
	 */
	public static String []sn = new String [4];
	
	public ReportControl() {
	}
	
	/**
	 * 	
	 * @param month
	 * @return satisfaction report details from month
	 */
	public static Object[][] mngSatRep(String month)
	{
		sn[0]="mngSatRep";
		sn[1]=month;
		ObjHandle.sendToServer(sn);
		data=new Object[((Object[][]) Main.clie.getResult()).length][9];
		return (Object[][]) Main.clie.getResult();
	}
	/**
	 * for net manager
	 * @param month 
	 * @return order report details from chosen month
	 */
	public static Object[][] mngOrderRep(String month)
	{
		sn[0]="mngOrdRep";
		sn[1]=month;
		ObjHandle.sendToServer(sn);
		data=new Object[((Object[][]) Main.clie.getResult()).length][8];
		for(int i=0 ; i<((Object[][]) Main.clie.getResult()).length ; i++)
			data[i][6] = new Boolean(null);
		return (Object[][]) Main.clie.getResult();
	}
	/**
	 * for net manager
	 * @param month
	 * @return inventory report details from chosen month 
	 */
	public static Object[][] mngInvRep(String month)
	{
		sn[0]="mngInvRep";
		sn[1]=month;
		ObjHandle.sendToServer(sn);
		data=new Object[((Object[][]) Main.clie.getResult()).length][5];
		return (Object[][]) Main.clie.getResult();
	}
	/**
	 * for net manager
	 * @param quarter 
	 * @return quarter income report details from chosen quarter
	 */
	public static Object[][] mngQuartIncRep(String quarter)
	{
		sn[0]="mngQuartIncRep";
		sn[1]=quarter;
		ObjHandle.sendToServer(sn);
		data=new Object[((Object[][]) Main.clie.getResult()).length][7];
		return (Object[][]) Main.clie.getResult();
	}
	/**
	 * for net manager
	 * @return complaint report details for complaint 
	 */
	public static Object[][] mngCompRep()
	{
		sn[0]="mngCompRep";
		ObjHandle.sendToServer(sn);
		data=new Object[((Object[][]) Main.clie.getResult()).length][9];
		return (Object[][]) Main.clie.getResult();
	}
	/**
	 * for store manager
	 * @return inventory details
	 */
	public static Object[][] getInventoryReport()
	{
		sn[0]="inventoryRep";
		
		ObjHandle.sendToServer(sn);
		
		data=new Object[((Object[][]) Main.clie.getResult()).length][3];
	    data= (Object[][]) Main.clie.getResult();
		return data;
	}
	/**
	 * for store manager
	 * @param Smonth = from month
	 * @param Emonth = until month
	 * @param type = handled or not handled complaints
	 * @return complaint details
	 */
	public static Object[][] getCompStatReport(String Smonth, String Emonth, String type)
	{
		sn[0] = "costumer complaint report";
		sn[3] = type;
		sn[1] = Smonth;
		if(!Emonth.equals(" "))
			sn[2] = Emonth;
		else
			sn[2] = Smonth;
		
		ObjHandle.sendToServer(sn);
		
		data=new Object[((Object[][]) Main.clie.getResult()).length][4];
	    data= (Object[][]) Main.clie.getResult();
		return data;
	}
	/**
	 * for store manager
	 * @param quarter 
	 * @return quarter income details
	 */
	public static Object[][] getIncomeReport(String quarter)
	{
		sn[0] = "quarter income report";
		sn[1] = quarter;
		
		ObjHandle.sendToServer(sn);
		
		data=new Object[((Object[][]) Main.clie.getResult()).length][5];
	    data= (Object[][]) Main.clie.getResult();
		return data;
	}
	/**
	 * for store manager
	 * @param month
	 * @return order details from month
	 */
	public static Object[][] getOrderRep(String month)
	{
		sn[0] = "get order report";
		sn[1] = month;
		
		ObjHandle.sendToServer(sn);
		
		data=new Object[((Object[][]) Main.clie.getResult()).length][6];
		for(int i=0 ; i<((Object[][]) Main.clie.getResult()).length ; i++)
			data[i][5] = new Boolean(null);
	    data= (Object[][]) Main.clie.getResult();
		return data;
	}
	/**
	 * save complaint report in database
	 * @param rid = report id
	 * @param cid = complaint id
	 * @param compensation = amount of compensation
	 */
	public static void saveCompRep(String rid, String cid, String compensation)
	{
		sn[0] = "save costumer report";
		sn[1] = rid;
		sn[2] = cid;
		sn[3] = compensation;
		
		ObjHandle.sendToServer(sn);
	}
	/**
	 * save costumer satisfaction report in database
	 * @param avg = line from satisfaction table
	 */
	public static void saveSatisRep(String []avg)
	{
		ObjHandle.sendToServer(avg);
	}
	/**
	 * save order report in database
	 * @param avg = line from order table
	 */
	public static void saveOrderRep(String []avg)
	{
		ObjHandle.sendToServer(avg);
	}
	/**
	 * save quarter income report in database
	 * @param avg = line from quarter income table
	 */
	public static void saveIncomeRep(String []avg)
	{
		ObjHandle.sendToServer(avg);
	}
	/**
	 * save inventory report in database
	 * @param avg = line from inventory table
	 */
	public static void saveInventoryRep(String []avg)
	{
		ObjHandle.sendToServer(avg);
	}
	/**
	 * 
	 * @param id = type of report
	 * @return next free report id to use
	 */
	public static int getRepID(int id)
	{
		sn[0] = "get report id";
		sn[1] = Integer.toString(id);
		sn[2] = "1";
		sn[3] = "1";
		
		ObjHandle.sendToServer(sn);
		
		int crID =  (Integer) Main.clie.getResult();
		return crID;
	}
	/**
	 * 
	 * @return satisfaction details
	 */
	public static Object [][] getSatisfactionReport()
	{
		sn[0] = "get satisfaction report";
		sn[1] = "1";
		sn[2] = "1";
		sn[3] = "1";
		
		ObjHandle.sendToServer(sn);
		
		data=new Object[((Object[][]) Main.clie.getResult()).length][7];
	    data= (Object[][]) Main.clie.getResult();
		return data;
		
	}
	
	
	

}
